package com.feicheng.persistence.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.feicheng.common.result.ResultInfo;
import com.feicheng.persistence.entity.CnRegionInfo;
import com.feicheng.persistence.mapper.CnRegionInfoMapper;
import com.feicheng.persistence.service.ICnRegionInfoService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author cailongyang
 * @since 2024-08-21
 */
@Service
public class CnRegionInfoServiceImpl extends ServiceImpl<CnRegionInfoMapper, CnRegionInfo> implements ICnRegionInfoService {

    @Override
    public ResultInfo getRegionByCodeAndScode(String code, String scode) {

        JSONObject param = new JSONObject();
        QueryWrapper<CnRegionInfo> qw = new QueryWrapper<>();

        //  省市区集合
        if (StringUtils.hasLength(code)) {
            qw.eq("scode", code);
        }

        if (StringUtils.hasLength(scode)) {
            qw.eq("scode", scode);
        }
        param.put("subs", list(qw));


        if (!StringUtils.hasLength(code)) {
            code = "110000";
        }
        param.put("region", getById(code));

        return ResultInfo.success(param);
    }
}
